<template>
  <div class="phone-register-login-container">
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="登录" name="login">
        <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0" class="login-form">
          <h3 class="title">手机快速登录</h3>
          <el-form-item prop="phone">
            <el-input v-model="loginForm.phone" placeholder="手机号"></el-input>
          </el-form-item>
          <el-form-item prop="code">
            <el-input v-model="loginForm.code" placeholder="验证码"></el-input>
            <el-button slot="append" @click="sendLoginCode">获取验证码</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleLogin">登录</el-button>
            <span style="margin-left: 20px;">还没有账号？<router-link to="/register">立即注册</router-link></span>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="注册" name="register">
        <el-form :model="registerForm" :rules="registerRules" ref="registerForm" label-width="0" class="register-form">
          <h3 class="title">手机快速注册</h3>
          <el-form-item prop="phone">
            <el-input v-model="registerForm.phone" placeholder="手机号"></el-input>
          </el-form-item>
          <el-form-item prop="code">
            <el-input v-model="registerForm.code" placeholder="验证码"></el-input>
            <el-button slot="append" @click="sendRegisterCode">获取验证码</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleRegister">注册</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>export default {
  data() {
    return {
      activeName: 'login',
      loginForm: {
        phone: '',
        code: ''
      },
      registerForm: {
        phone: '',
        code: ''
      },
      loginRules: {
        phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      },
      registerRules: {
        phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      }
    };
  },
  methods: {
    sendLoginCode() {
      // 发送登录验证码逻辑，例如：
      this.$message('发送登录验证码');
      // 实际开发中请替换为真实发送验证码的API调用
    },
    sendRegisterCode() {
      // 发送注册验证码逻辑，例如：
      this.$message('发送注册验证码');
      // 实际开发中请替换为真实发送验证码的API调用
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          // 发送登录请求
          // 实际开发中请替换为真实登录的API调用
          this.$http.post('/api/login', this.loginForm).then(response => {
            // 登录成功后的处理
          }).catch(error => {
            // 处理错误
          });
        } else {
          console.log('登录失败，请检查输入信息');
        }
      });
    },
    handleRegister() {
      this.$refs.registerForm.validate(valid => {
        if (valid) {
          // 发送注册请求
          // 实际开发中请替换为真实注册的API调用
          this.$http.post('/api/register', this.registerForm).then(response => {
            // 注册成功后的处理
          }).catch(error => {
            // 处理错误
          });
        } else {
          console.log('注册失败，请检查输入信息');
        }
      });
    }
  }
};
</script>

<style scoped>.phone-register-login-container {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f5f7fa;
}
.title {
  text-align: center;
  margin-bottom: 20px;
}
.login-form,
.register-form {
  width: 300px;
}
</style>
